﻿namespace iFinance.Modules.Outgoings.ViewModels
{
    using System;
    using System.Windows.Controls;
    using iFinance.Infrastructure;
    using iFinance.Infrastructure.Services;
    using iFinance.Infrastructure.ViewModels;
    using Microsoft.Practices.Prism.ViewModel;
    using Microsoft.Practices.Unity;

    /// <summary>
    /// 支出项ViewModel
    /// </summary>
    public class OutgoingsItemViewModel : NotificationObject
    {
        #region Ctor

        public OutgoingsItemViewModel()
            : this(new Entity.Outgoings())
        {
        }

        public OutgoingsItemViewModel(Entity.Outgoings outgoings)
        {
            this.RealData = outgoings;
            if (outgoings != null)
            {
                //初始化支出类别
                var basicInfoService = UnityHelper.Container.Resolve<IBasicInfoService>();
                if (basicInfoService != null)
                {
                    this.OutgoingsType = basicInfoService.GetOutgoingsType(outgoings.TypeID);
                }
            }
        }

        #endregion

        #region 属性

        /// <summary>
        /// 代理的实际数据
        /// </summary>
        public Entity.Outgoings RealData { get; set; }

        /// <summary>
        /// 支出时间
        /// </summary>
        public DateTime Date
        {
            get { return RealData.Date; }
            set
            {
                if (RealData.Date != value)
                {
                    RealData.Date = value;
                    RaisePropertyChanged(() => this.Date);
                }
            }
        }

        /// <summary>
        /// 支出地点
        /// </summary>
        public string Location
        {
            get { return RealData.Location; }
            set
            {
                if (RealData.Location != value)
                {
                    RealData.Location = value;
                    RaisePropertyChanged(() => this.Location);
                }
            }
        }

        /// <summary>
        /// 支出说明
        /// </summary>
        public string Description
        {
            get { return RealData.Description; }
            set
            {
                if (RealData.Description != value)
                {
                    RealData.Description = value;
                    RaisePropertyChanged(() => this.Description);
                }
            }
        }

        /// <summary>
        /// 支出总额
        /// </summary>
        public decimal TotalAmount
        {
            get { return RealData.TotalAmount; }
            set
            {
                if (RealData.TotalAmount != value)
                {
                    RealData.TotalAmount = value;
                    RaisePropertyChanged(() => this.TotalAmount);
                }
            }
        }

        private OutgoingsTypeItemViewModel outgoingsType = null;

        /// <summary>
        /// 支出类别项
        /// </summary>
        public OutgoingsTypeItemViewModel OutgoingsType
        {
            get { return this.outgoingsType; }
            set
            {
                if (this.outgoingsType != value)
                {
                    this.outgoingsType = value;
                    RaisePropertyChanged(() => this.OutgoingsType);
                }
            }
        }

        /// <summary>
        /// 最近一次更改时间
        /// </summary>
        public DateTime LastModifyDate
        {
            get { return RealData.LastModifyDate; }
            set
            {
                if (RealData.LastModifyDate != value)
                {
                    RealData.LastModifyDate = value;
                    RaisePropertyChanged(() => this.LastModifyDate);
                }
            }
        }

        private OutgoingsDetailViewModel outgoingsDetail = new OutgoingsDetailViewModel();

        /// <summary>
        /// 支出明细
        /// </summary>
        public OutgoingsDetailViewModel OutgoingsDetail
        {
            get { return this.outgoingsDetail; }
            set
            {
                if (this.outgoingsDetail != value)
                {
                    this.outgoingsDetail = value;
                    RaisePropertyChanged(() => this.OutgoingsDetail);
                }
            }
        }

        private bool isChecked = false;
        /// <summary>
        /// 是否选中这一条记录
        /// </summary>
        public bool IsChecked
        {
            get { return this.isChecked; }
            set
            {
                if (this.isChecked != value)
                {
                    this.isChecked = value;
                    RaisePropertyChanged(() => this.IsChecked);
                }
            }
        }

        private bool isDetailLoaded = false;
        /// <summary>
        /// 支出明细是否已经被加载
        /// </summary>
        public bool IsDetailLoaded
        {
            get { return this.isDetailLoaded; }
            set { this.isDetailLoaded = value; }
        }

        #endregion        
    }

    /// <summary>
    /// 支出列表ViewModel
    /// </summary>
    public class OutgoingsListViewModel : ObservableObjectCollection
    {
    }
}
